<?php if (
    !$this->di->auth->getUserId() 
    && ($_SERVER['REQUEST_METHOD'] != 'POST')
    && (empty($_GET['_qf_EmailCode_display']))): // skip this block if user is logged-in ?>
<div id="fb-root"></div>

<a href="javascript:" onclick="facebook_connect()"><?php echo $plugin->renderConnect()?></a>

<script type="text/javascript">
        
  window.fbAsyncInit = function() {
    FB.init({
      appId  : '<?php j($plugin->getConfig('app_id'))?>',
      status : true, // check login status
      cookie : true, // enable cookies to allow the server to access the session
      xfbml  : true,  // parse XFBML
      channelUrl  : 'http://www.yourdomain.com/channel.html', // Custom Channel URL
      oauth : true //enables OAuth 2.0
    });
    FB.getLoginStatus(function(response){ }); 
  };

  (function() {
    var e = document.createElement('script');
    e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
    e.async = true;
    document.getElementById('fb-root').appendChild(e);
  }());
    
function facebook_connect()
{
 FB.login(function(response) {
   if (response.authResponse) {
     FB.api('/me', function(response) {
       jQuery("input[name='name_f']").val(response.first_name);
       jQuery("input[name='name_l']").val(response.last_name);
       jQuery("input[name='email']").val(response.email);
     });
   } else {
     // User cancelled login or did not fully authorize
   }
 }, {scope: 'email'});    
}

</script>
<?php endif; // end of skip if customer is not logged-in ?>